package com.fulihui.usercore.biz.conv;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.collections.CollectionUtils;

import com.fulihui.usercore.condition.CooperationInfoCondition;
import com.fulihui.usercore.dal.dataobj.CooperationInfoDO;
import com.fulihui.usercore.dto.CooperationInfoDTO;
import com.fulihui.usercore.request.merchant.CooperationInfoSaveRequest;

/**
 * @author Willard.Hu on 2016/9/25.
 */
public class CooperationInfoConv {

    public static CooperationInfoDO toDO(CooperationInfoSaveRequest request) {
        if (request == null) {
            return null;
        }
        CooperationInfoDO dataobj = new CooperationInfoDO();
        dataobj.setId(request.getId());
        dataobj.setMid(request.getMid());
        dataobj.setMethod(request.getMethod());
        dataobj.setPartnerId(request.getPartnerId());
        dataobj.setPartnerName(request.getPartnerName());
        dataobj.setConnType(request.getConnType());
        dataobj.setStartDate(request.startDate());
        dataobj.setEndDate(request.endDate());
        return dataobj;
    }

    public static CooperationInfoDO toDO(CooperationInfoCondition condition) {
        if (condition == null) {
            return null;
        }
        CooperationInfoDO dataobj = new CooperationInfoDO();
        dataobj.setMid(condition.getMid());
        return dataobj;
    }

    public static CooperationInfoDTO toDTO(CooperationInfoDO dataobj) {
        if (dataobj == null) {
            return null;
        }
        CooperationInfoDTO dto = new CooperationInfoDTO();
        dto.setId(dataobj.getId());
        dto.setMid(dataobj.getMid());
        dto.setMethod(dataobj.getMethod());
        dto.setPartnerId(dataobj.getPartnerId());
        dto.setPartnerName(dataobj.getPartnerName());
        dto.setConnType(dataobj.getConnType());
        dto.startDate(dataobj.getStartDate());
        dto.endDate(dataobj.getEndDate());
        dto.gmtCreate(dataobj.getGmtCreate());
        dto.gmtModified(dataobj.getGmtModified());
        return dto;
    }

    public static List<CooperationInfoDTO> toList(List<CooperationInfoDO> doList) {
        if (CollectionUtils.isEmpty(doList)) {
            return Collections.emptyList();
        }
        return doList.stream().map(CooperationInfoConv::toDTO).collect(Collectors.toList());
    }

}
